<%@page import="doantotnghiep.modelDTO.MedicamentDTO"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.HashMap"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Thêm chi tiết đặt hàng</title>

</head>
<body>
	<% HashMap<String, Object> orderModel = (HashMap<String, Object>) request.getAttribute("orderDetailModel");
	   float tong=0;
 		%>
	<div align="center">
		<h1 style="color: blue;"></h1>
		<form:form method="POST" commandName="PurchaseOrderDetailDTO">
			<tr>
			    <td><input type="text" value="Nhập tên dược phẩm" id ="medicinekeyword"
				onfocus="if (this.value == 'Nhập tên dược phẩm') {this.value = '';}"
				onblur="if (this.value == '') {this.value = 'Nhập tên dược phẩm';}" /></td>
			
				<td><span id="medicinename-error" style="color:red;display: none;"> </span></td>
			
				<td><input type="button" id="medicinesearch" value="Tìm kiếm" /></td>
			</tr>
			<tr>
				<td><form:label path="medicament_ID">Tên dược phẩm:</form:label></td>
				<td><form:select path="medicament_ID" value="${medicament_ID}">
						<%
			            if(orderModel!=null){
			            	int i =0;
   					    	 ArrayList<MedicamentDTO> medicamentDTOs =(ArrayList<MedicamentDTO>) orderModel.get("medicamentDTOs");
   					   		 if(medicamentDTOs!=null){
   					         	for (i = 0; i < medicamentDTOs.size(); i++) { %>
								 <option value="<%=medicamentDTOs.get(i).getId()%>"><%=medicamentDTOs.get(i).getMedicamentName()%></option>
   	   					     <%}}}%>
   					         </form:select></td>	
   					     <%if(orderModel!=null){
      					     ArrayList<MedicamentDTO> medicamentDTOs =(ArrayList<MedicamentDTO>) orderModel.get("medicamentDTOs");
      					   		 if(medicamentDTOs!=null){
      					   			 for (int j = 0; j < medicamentDTOs.size(); j++) {%>
						<td><input type = "text" style="display: none" id="numberBatch<%=j%>" value="<%=medicamentDTOs.get(j).getTotalOfBatch()%>"></td>
								<%}
   	   					     }
   					   	}%>
			</tr>
			<tr>
				<td><form:label path="totalBatch">Số lượng lô:</form:label></td>
				<td><form:input id ="totalBatch" path="totalBatch" value="${totaBatch}"></form:input></td>
			</tr>
			<tr>
				<td><input id="addorderdetail" type="button" value="Thêm" /></td>
			</tr>
		</form:form>
		<div id="purchasedetail" align="center">
			<h1 style="color: blue;">CHI TIẾT ĐẶT HÀNG</h1>
			<table class="table1" id="purchasedetailtable">
				<tr>
					
					<th scope="col" abbr="Starter">Mã dược phẩm</th>
					<th scope="col" abbr="Starter">Tên dược phẩm</th>
					<th scope="col" abbr="Starter">Sô lượng lô</th>
					<th scope="col" abbr="Starter">Thành tiền</th>
					<th scope="col" abbr="Starter"></th>
					<th scope="col" abbr="Starter"></th>
				</tr>
			    
				 <c:forEach items="${orderDetailModel.purchaseOrderDetailDTOs}" var="detail"
							varStatus="status">
							<tr class="<c:if test="${status.count % 2 == 0}">even</c:if>">
				<tr>
					<td>${detail.medicament_ID}</td>
					<td>${detail.medicamentName}</td>
					<td>${detail.totalBatch}</td>
					<td>${detail.orderCost}</td>
					
					<td><a href="#"> <img
							src="<c:url value="/resources/images/edit-icon.png"/>" /></a></td>
					<td><a href="#"> <img
							src="<c:url value="/resources/images/delete-icon1.png"/>" /></a></td>
				</tr>
				</c:forEach>
			</table>
			<div id="purchasedetailpaging"></div> 
			<input id="submitorder" type="button" value="Lập đơn bán hàng" />
			<input id="closeordertable" type="button" value="Đóng" />
			<script type="text/javascript">
						var pager = new Pager('purchasedetailtable', 5);
						pager.init();
						pager.showPageNav('pager', 'purchasedetailpaging');
						pager.showPage(1);
					</script>
		</div>
	</div>
</body>
</html>